<template>
	<view id="app">
        <view v-for="(item,index) in address" :key="index" @click="goreturn(item)" class="list">
            <view>
                <ul>
                    <li>{{item.receive_name}}</li>
                    <li>{{item.receive_phone}}</li>
                    <li v-if="item.is_default == 1" class="moren">默认</li>
                </ul>
                <view class="address">收货地址：{{item.cri_name}} {{item.address}}</view>
            </view>
			<view @click.stop="goEdit(item)">
				<u-icon class="bianji" name="edit-pen"></u-icon>
			</view>
        </view>
        <button @click="goEdit()" class="add-btn">新建地址</button>
    </view>
</template>

<script>
	export default {
		data() {
			return {
				address:[],
				source:''
			}
		},
		onShow() {
			// this.getAddress();
		},
		onLoad(option){
			this.source = option.source;
		},
		methods: {
			goEdit(item){
				uni.navigateTo({
					url:'/pages/Address/editAddress?list='+JSON.stringify(item)
				})
			},
			getAddress(){
				this.$https.Address.getAddress()
						.then(res=>{
							this.address = res;
							this.address.forEach(item=>{
								item.cri_name = "";
								item.show_address.forEach(step=>{
									item.cri_name += step
								})
							})
						})
			},
			goreturn(item){
				if(this.source){
					this.$api.prePage().addressData = item;
					// this.$bus.$emit('address',id);
					uni.navigateBack();
				}
			}
		},
	}
</script>

<style lang="scss">
#app {
  padding-bottom: 200rpx;
  font-size: $uni-font-size-base;
  padding-top: 12rpx;
}
.list{
  margin: 20rpx 32rpx 0;
  border: 2rpx solid #F2F2F2;
  border-radius: 16rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx 16rpx;
  .bianji{
    color: $uni-color-primary;
    font-size: 46rpx;
  }
  ul{
    list-style: none;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 0;
    margin: 0 0 20rpx 0;
    li{
      padding-right: 20rpx;
    }
    .moren{
      margin: 0 0 0 30rpx;
      padding: 0;
      background: $uni-color-primary;
      color: #fff;
      border-radius: 30rpx;
      padding: 0 16rpx;
    }
  }
  .address{
    font-size: $uni-font-size-sm;
    color: $uni-text-color-grey;
  }
}
.add-btn{
  width: 90%;
  display: block;
  border: none;
  height: 80rpx;
  line-height: 80rpx;
  font-size: $uni-font-size-base;
  color: #fff;
  background: $uni-color-primary;
  border-radius: 200rpx;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto 60rpx;
  outline: none;
}
</style>